package com.example.demo.study.designmode.creational.singleton;


import org.junit.Assert;
/**
 * DCL（double check lock双重检查锁）
 */
public class Lazy {
    //保证可见性和有序性
    public volatile static Lazy role;
    public Lazy(){}
    //保证原子性
    public synchronized static Lazy getInstance()
    {
        if(role==null)
        {
            role=new Lazy();
            return role;
        }
        return role;
    }

    public static void main(String[] args) {
        Lazy s1= Lazy.getInstance();
        Lazy s2= Lazy.getInstance();
        Assert.assertEquals(s1,s2);
    }
}
